﻿using System;

using System.Collections.Generic;
using System.Text;
using Silvermoon.Controls;
using System.Drawing;
using Silvermoon.Shapes;
using System.Diagnostics;
using Silvermoon.Controls.Base;

namespace Silvermoon.Core
{
    /// <summary>
    /// Provides layout functionality.
    /// </summary>
    internal static class Layouter
    {

        /// <summary>
        /// Sets the boundaries of a control depending on the container's size and it's margins.
        /// </summary>
        /// <param name="control">The control for which to set the Bounds.</param>
        /// <param name="parent">The size of the parent container.</param>
        public static void Layout(Control control, Size containerSize)
        {
            control.Bounds = control.Margin.Layout(control.Bounds, containerSize);

        }

        /// <summary>
        /// Sets the boundaries of all children of a control that implements ICompositeControl relative to the size of this control and their margins.
        /// </summary>
        /// <param name="control">A control which must implement ICompositieControl.</param>
        public static void LayoutChildren(Control control)
        {            
            var children = control.VisibleControls;
            if (children != null)
            {

                Size size = control.Size;
                Control c = children.First;
                while (c != null)
                {
                    if (!c.Margin.IsEmpty) Layout(c, size);
                    c = c.NextControl;
                }
            }
        }
    }
}
